package com.zlz.open.ugs.adaptor.source;

import com.zlz.open.ugs.common.config.entity.ApiEntity;
import com.zlz.open.ugs.common.config.entity.runtime.UgsServe;
import com.zlz.open.ugs.common.config.entity.runtime.UgsUrl;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @Author: zhulinzhong
 * @Date: 2024/5/21
 */
@Primary
@Component
public class RedisSourceLoaderAdaptor implements SourceLoaderAdaptor {
    @Override
    public UgsUrl getUrl(String url) {
        UgsUrl ugsUrl = new UgsUrl();
        ugsUrl.setUrl("/url/test/json");
        ugsUrl.setMethods(new HashSet<>(Arrays.asList("GET","POST")));
        ugsUrl.setEncodingType("UTF-8");
        ApiEntity apiEntity = new ApiEntity();
        apiEntity.setUrl("http://127.0.0.1:8081/api/test/json");
        apiEntity.setMethod("GET");
        apiEntity.setParamTemplate("<xml>\n"
                + "<header>${header.name!}</header>\n"
                + "<name>${body.name!}</name>\n"
                + "<age>${body.age!}</age>\n"
                + "</xml>\n");
        ugsUrl.setApiEntity(apiEntity);
        if (url.equals(ugsUrl.getUrl())) {
            return ugsUrl;
        }
        return null;
    }

    @Override
    public List<UgsServe> getServes() {
        List<UgsServe> serves = new ArrayList<>();
        UgsServe ugsServe = new UgsServe();
        ugsServe.setName("富友");
        UgsServe ugsServe2 = new UgsServe();
        ugsServe2.setName("拉卡拉");
        serves.add(ugsServe);
        serves.add(ugsServe2);
        return serves;
    }
}
